<?php

class Test_Abovo_Form extends Solar_Test {
    
    public function setup()
    {
        $this->_form = Solar::factory('Abovo_Form');
    }
    
    public function testSetElements()
    {
        $elements = array(
            'name' => array(
                'type' => 'text',
                'filter' => array('validateAlpha'),
            ),
            'genre' => array(
                'type'   => 'text',
                'filter' => array(
                    'sanitizeInt',
                    array('validateInlist', 'VALIDATE_INLIST', array(0, 1)),
                ),
            ),
            'age' => array(
                'type'   => 'text',
                'filter' => array('validateInt'),
            ),
            'email' => array(
                'type'   => 'text',
                'filter' => array('validateEmail'),
            ),
        );
        
        $this->_form->setElements($elements);
        
        $data = array(
            'name'  => 'Antti',
            'genre' => 'antti0hello',
            'age'   => 23,
            'email' => '@gmail.com',
        );
        
        $this->_form->populate($data);
        
        $validated = $this->_form->validate();
        $values = $this->_form->values();
        
        $this->assertFalse($validated);
        $this->assertSame($values['genre'], 0);
        
        $this->assertTrue($this->_form->elements['name']['status']);
        
        $this->assertFalse($this->_form->getStatus());
    }
}